﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace Douban.Core.Commands
{
    public class UIElementClickCommandBehavior : CommandBehaviorBase<UIElement>
    {
        private bool _isPrepared = false;

        public UIElementClickCommandBehavior(UIElement target) : base(target)
        {
            target.MouseLeftButtonDown += (sender, e) =>
            {
                e.Handled = true;
                _isPrepared = true;
            };

            target.MouseLeftButtonUp += target_MouseLeftButtonUp;
        }

        private void target_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (_isPrepared)
            {
                e.Handled = true;
                _isPrepared = false;
                ExecuteCommand();
            }
        }
    }
}
